<!DOCTYPE html>
<html class="no-js">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1,user-scalable=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp"/>
  <!-- 启用360浏览器的极速模式(webkit) -->
  <meta name="renderer" content="webkit">
  <!-- 避免IE使用兼容模式 -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
  <meta name="HandheldFriendly" content="true">
  <!-- 微软的老式浏览器 -->
  <meta name="MobileOptimized" content="320">
  <!-- uc强制竖屏 -->
  <meta name="screen-orientation" content="portrait">
  <!-- QQ强制竖屏 -->
  <meta name="x5-orientation" content="portrait">
  <!-- UC强制全屏 -->
  <meta name="full-screen" content="yes">
  <!-- QQ强制全屏 -->
  <meta name="x5-fullscreen" content="true">
  <!-- UC应用模式 -->
  <meta name="browsermode" content="application">
  <!-- QQ应用模式 -->
  <meta name="x5-page-mode" content="app">
  <!-- windows phone 点击无高光 -->
  <meta name="msapplication-tap-highlight" content="no">
	<script type="text/javascript" src="{{ asset('js/jquery-1.8.3.min.js') }}"></script>
  <!-- 适应移动端end -->
	<title>药剂师工作台</title>
	<link rel="stylesheet" href="{{asset('myhome/css/css_stylen.css')}}">
	<link rel="stylesheet" href="{{ asset('myhome/css/headerl.css') }}">
	<link rel="stylesheet" href="{{ asset('myhome/css/font.css') }}">
    <link rel="stylesheet" href="{{ asset('css/index.css') }}"/>
	<style>
		.zt {
			float: right!important;
			color: white!important;
			height: 30px!important;
			width: 26%!important;
			background-color: rgba(233, 104, 98, 0.95)!important;
			border-radius: 5px!important;
			text-align: center!important;
			line-height: 30px!important;
			margin-right: 1.8rem!important;
		}

		.zt_a {
			float: right;
			background-color: #888888;
			height: 30px;
			width: 150px;
			border-radius: 5px;
			text-align: center;
			line-height: 30px;
			margin-right: 1.5rem;
		}

		.zt_b {
			color: white!important;
			float: right!important;
			background-color: #2cb6b4!important;
			height: 30px!important;
			width: 150px!important;
			border-radius: 5px!important;
			text-align: center!important;
			line-height: 30px!important;
			margin-right: 1.8rem!important;
		}
		#did span{
			font-size: 15px;
		}
		#order_list h2,#order_list h3,#order_list h4,#order_list b{
			margin-left: 120px;
		}
		#order_list li{
			margin-bottom: 0px;

		}
		.zw{
			width: 100%;
			height: 150px;
			background-color: #7d8289;
		}
		.order_header{
			background-color: #fafafa;
		}
	</style>
	<script type="text/javascript" src="{{asset('js/zepto.min.js')}}"></script>

</head>
<body>
	<div id="user-b">
		<!--html5 nav-->

	    <div class="myorder-tab">
	    	<div class="myorder-nav">
		    	<ul id="tab_btn" class="coupon-list">
		    		<li class="pick" id="l1" >咨询列表 </li>
		    		<li  ><span class="bar" id="l2" ></span>审核列表</li>
		    		<li  ><span class="bar" id="l3" onclick="check()"></span>个人中心</li>
		    	</ul>
		    	<div class="cl"></div>
		    </div>
		    <div class="myorder-content">
		    	<ul >
		    		<li class="mc-all cc-one tab_content show">
		    			<ul id="did">
							@foreach($list as $k=>$v)
		    				<li>
		    					<a href="{{ url('/chat/send/'.$v->sender_id) }}">
		    						<div class="mc-sum-box">
			    						<div class="myorder-sum fl"><img src="@if(strstr($v->photo,"http://wx.qlogo.cn")) {{ $v->photo }} @else {{ url('upload/user/'.$v->photo) }} @endif"><p class='tishi' style='display:none' >0</p></div>
				    					<div class="myorder-text">
				    						<h1><span class='tith1' id="name">{{ $v->nickname }} </span ><span class='tith2' id="time">{{ $v->created_at }}</span></h1>

				    						<div class="myorder-cost">
				    							<span id="content">{{ $v->content }}</span>

				    						</div>
				    					</div>
			    					</div>

		    					</a>
		    				</li>
							@endforeach
		    			</ul>
		    		</li>
		    		<li class="mc-all mc-two tab_content">
						<div id="didd">


						</div>
		    		</li>
		    		<li class="mc-all mc-three tab_content">
						<section class="m-component-user" id="m-user">
							<div class="m-user-avatar text-center">
								<span class="avatarPic"><img id="photo" style="display: inline;" class="lazy img-circle" src="{{asset('upload/doctor/doc_default.jpg')}}" ></span>
								<div class="user_btn">
									<a href="javascript:void (0)" onclick="change('1')" class="this" id="a1">上班</a>
									<a href="javascript:void (0)" onclick="change('2')" id="a2">休息</a>
								</div>
							</div>

							<div class="head_list">
								<ul class="m-user-list " id="list1">
									<li style="height:44px"><span id="count" > </span><br>已解决</li>
									<li><a href="coupon.html"><span class="bar" ></span><span id="good">  </span><br>好评</a></li>
									<li><a href="myorder.html"><span class="bar"></span><span id="order">  </span ><br>审核订单</a></li>
								</ul>
							</div>
							<ul class="m-user-content">
								<li>
									<div class="m-user-item">
										<a href="/doctor/docinfo" class="user-order">账户设置</a>
									</div>
									<div class="m-user-item">
										<a href="/doctor/credinfo" class="user-coupon">资质管理</a>
									</div>
								</li>
								<li>
									<div class="m-user-item">
										<a href="#" class="user-site">系统通知</a>
									</div>
									<div class="m-user-item">
										<a href="{{url('logout/home')}}" class="user-set">退出</a>
									</div>

								</li>

							</ul>
						</section>
		    		</li>
		    	</ul>
		    </div>
	    </div>
	    <!--footer begin-->

	    <!--footer end-->
	</div>
	<script type="text/javascript">

	var mytime=0;

    var tab_Btns_box=document.getElementById('tab_btn');
    var tab_Btns=tab_Btns_box.getElementsByTagName('li');
    var tab_contents=document.getElementsByClassName('tab_content');
    var pdl="";

    @if(isset($msg))
        alert("{{ $msg }}");
	@endif

    for(var i=0;i<tab_Btns.length;i++){
    	tab_Btns[i].index=i;
		tab_Btns[i].onclick=function() {
            for (var i = 0; i < tab_Btns.length; i++) {
                if (i !== this.index) {
                    tab_Btns[i].classList.remove('pick')
                }
            }
            tab_Btns[this.index].className = "pick";
            for (var j = 0; j < tab_contents.length; j++) {
                if (j !== this.index) {
                    tab_contents[j].classList.remove('show');
                } else {
                    pdl = j; //记录第几个选项卡被选中
                }
                tab_contents[this.index].classList.add('show');
            }
			//控制定时器开启
            if (pdl == 2) {
                doStop();

            } else if(pdl==1){
                doStop();

			}else{
                goon();
			}
        }
    }
    select();
	//定时器停止
    function doStop(){
        if(mytime!=0){
            clearInterval(mytime);
            mytime = 0;
        }
    }
    //定时器继续
    function goon(){
        if(mytime==0){
            mytime = setInterval(dosel,1000);
        }
    }
    mytime = setInterval(dosel, 1000);

    var n=0;
	var leng="";
	var strr='';
	var style="style='display:none'"
	//拼接格式时间
    function getMyDate(str){
        var oDate = new Date(str),
            oYear = oDate.getFullYear(),
            oMonth = oDate.getMonth()+1,
            oDay = oDate.getDate(),
            oHour = oDate.getHours(),
            oMin = oDate.getMinutes(),
            oSen = oDate.getSeconds(),
            oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间
        return oTime;
    }
    //时间戳加零
    function getzf(num){
        if(parseInt(num) < 10){
            num = '0'+num;
        }
        return num;
    }
    //请求聊天记录
    function dosel()
	{
		$.ajax({
            url: '{{url("doctor/askinfo")}}',
            type: 'POST',
            dataType: 'json',
            cache: false,
            data: { _token: "{{ csrf_token() }}" },
			success:function(data){

                if(n==0){
                    n++;
                    leng=data.length;
                    for(var i=0;i<data.length;i++)
                    {

                        if(data[i].count==0){
                            $("#count"+i).css("display","none");
                        }else{
                           // $("#count"+i).attr("style='display:block'");
                            $("#count"+i).css("display","block");

                        }
                        var photo=data[i].photo;
						if(photo.indexOf("http://wx.qlogo.cn")==-1){
                            photo="/upload/user/"+data[i].photo;
						}else{
                            photo=data[i].photo;
						}
                        var time=getMyDate(parseInt(data[i].time));
                        var str ="<li><a href='/chat/send/"+data[i].sender_id+" ' ><div class='mc-sum-box'><div class='myorder-sum fl'><img src='"+photo+"'><p class='tishi' style='display: none'  id='count"+i+"' >"+data[i].count+"</p></div><div class='myorder-text'><h1><span class='tith1' id='name'>"+data[i].nickname+"</span ><span class='tith2' id='time"+i+"'>"+time+"</span></h1><div class='myorder-cost'><span id='content"+i+"' >"+(data[i].content)+"</span></div></div></div></a></li>";
                        strr=strr+str;
                        var tip = $(strr);
                        $("#did").html(tip);
                        if(data[i].count==0){
                            $("#count"+i).css("display","none");
                        }else{
                            // $("#count"+i).attr("style='display:block'");
                            $("#count"+i).css("display","block");

                        }

                    }
				}else if(n>0 && data.length>leng){
                    if(data[adta.length-1].count==0){
                        $("#count"+i).css("display","none");
                    }else{
                        // $("#count"+i).attr("style='display:block'");
                        $("#count"+i).css("display","block");

                    }
						var photo=data[i].photo;
						if(photo.indexOf("http://wx.qlogo.cn")==-1){
							photo="/upload/user/"+data[i].photo;
						}else{
							photo=data[i].photo;
						}
                        var time=getMyDate(parseInt(data[0].time));
                    	var str ="<li><a href='/chat/send/"+data[0].sender_id+" ' ><div class='mc-sum-box'><div class='myorder-sum fl'><img src='"+photo+"'><p class='tishi' "+style1+"  style='display: none' id='count"+i+"' >"+data[0].count+"</p></div><div class='myorder-text'><h1><span class='tith1' id='name'>"+data[0].nickname+"</span ><span class='tith2' id='time"+i+"'>"+time+"</span></h1><div class='myorder-cost'><span id='content"+i+"' >"+(data[0].content)+"</span></div></div></div></a></li>";
                        //var str ="<li><a href= ><div class='mc-sum-box'><div class='myorder-sum fl'><img src= ></div><div class='myorder-text'><h1><span class='tith1' id='name'>"+data[data.length-1].nickname+"</span ><span class='tith2' id='time'>"+time+"</span></h1><div class='myorder-cost'><span id='content'>"+(data[data.length-1].content)+"</span></div></div></div></a></li>";
                        strr=str+strr;
                        var tip = $(strr);
                        $("#did").html(tip);
                        leng=data.length;

					if(data[adta.length-1].count==0){
                        $("#count"+i).css("display","none");
                    }else{
                        // $("#count"+i).attr("style='display:block'");
                        $("#count"+i).css("display","block");

                    }

				}else{
				    //alert(1111);
                    for(var i=0;i<data.length;i++)
                    {
                        if(data[i].count==0){
                            $("#count"+i).css("display","none");
						}else{
                            $("#count"+i).css("display","block");
						}
                        var time=getMyDate(parseInt(data[i].time));
                        //alert(data[i].count);
                        $("#count"+i).html(data[i].count);
                        $("#content"+i).html(data[i].content);
                        $("#time"+i).html(time);
                    }
				}

            },
            error: function(data) {

            },
		});
    }
    //查询药师信息
	function select() {
        $.ajax({
            url: '{{url("doctor/selt")}}',
            type: 'POST',
            dataType: 'json',
            cache: false,
            data: {_token: "{{ csrf_token() }}"},
            success:function (data) {
                    if(data[0].status=="1"){
                        $("#a2").css('color',"#e94343");
                        $("#a1").css('color',"white");
                        $("#a2").css('background',"white");
                        $("#a1").css('background',"#e94343");
                    }else{
                        $("#a1").css('color',"#e94343");
                        $("#a2").css('color',"white");
                        $("#a1").css('background',"white");
                        $("#a2").css('background',"#e94343");
                    }
                    $("#order").html(data[0].order);
                    $("#count").html(data[0].count);
                    $("#good").html(data[0].good);
                    //alert(data[0].photo);
                    $("#photo").attr('src','/upload/doctor/'+data[0].photo);

            },

        })
    }
	//个人设置
	function change(a) {
        $.ajax({
            url: '{{url("doctor/csta")}}',
            type: 'POST',
            dataType: 'json',
            cache: false,
            data: {_token: "{{ csrf_token() }}",'status':a},
			success:function (data) {
				if(data==1){
                    if(a == "1"){
                        $("#a2").css('color',"#e94343");
                        $("#a1").css('color',"white");
                        $("#a2").css('background',"white");
                        $("#a1").css('background',"#e94343");
                    }else{
                        $("#a1").css('color',"#e94343");
                        $("#a2").css('color',"white");
                        $("#a1").css('background',"white");
                        $("#a2").css('background',"#e94343");
                    }
				}
            },

		})
    }
    </script>

	<script type="text/javascript">
        var str = " ";
        redata();
        setInterval(redata, 100000)
        //请求新订单数据
        function redata() {

            $.ajax({
                url: '{{url("doctor/redata")}}',
                type: 'POST',
                async: false,
                dataType: 'json',
                //cache: false,
                data: {_token: "{{ csrf_token() }}"},

                success: function (data) {
                    var str = "";
                    for (var i = 0; i < data.length; i++) {
                        //转换时间戳
                        var iclass="";
                        var ts="";
                        var time = [];
                        var date = data[i].order.pay_at;
                        date = date.replace(/-/g, '/');
                        time = new Date(date).getTime();
                        var ntime = new Date().getTime();
                        var stime = 40 - Math.round((ntime - time) / 60000);
                        var ltime = stime + '分钟';
                        if (stime < 0) {
                            ltime = "已超时";
                        }
                        //alert(ltime);
                        str = str + "<div id='zw'></div><div class='order_box'> <div class='order_header'> <h2>订单编号: " + data[i].order.number + "</h2> <h3>收&nbsp;货&nbsp;人&nbsp;: <a>" + data[i].order.name + "</a>    </h3>  <h3>收货地址: <a >" + data[i].order.address + "</a></h3> <h3>配送时间:<a>2016-12-27 10:35</a>       &nbsp;&nbsp;&nbsp; 剩余时间<a> " + ltime + "</a></h3> <span class='up_icon'></span> <h3></li></a><li class='zt' id='zt'  onclick='chstu("+"2"+","+data[i].order.id+")'>审核通过</li><li class='zt' id='zt'  onclick='chstu("+"1"+","+data[i].order.id+")'>取消订单</li><a href='tel:" + data[i].order.phone + "'><li  class='icon-tel zt' >联系顾客</li></a></h3></div>";
                        for (var j = 0; j < data[i].order_info.length; j++) {
                            str = str + " <ul class='order_list' id='order_list' style='display: none'> <li> <a href='javascript:viod(0)'> <i class='pic'><img src='/upload/product/" + data[i].order_info[j].preview + "'/></i> <h2>" + data[i].order_info[j].name + "</h2> <h3>规格<span>" + data[i].order_info[j].specifications + "</span></h3> <h4> X" + data[i].order_info[j].count + "</h4> <b>" + data[i].order_info[j].price + "元</b> </a> </li> </ul>";
                        }
                        str = str + "</div>";

                    }
//                /alert(str);
                    var tip = $(str);
                    $("#didd").html(tip);
                    $(".order_box").click(function () {
                        $(this).find(".order_list").toggle();
                    });

                },
                error: function (data) {
                }
            });
        }
        function chstu(a,id) {
            var tapp="";
            if(a==1){
                tapp="确定要取消订单吗？";
			}else if(a==2){
                tapp="确认审核通过？";
			}
            if(confirm(tapp)){
				$("#zt").attr('class','zt_b');
				$.ajax({
					url: '{{url("doctor/chstu")}}',
					type: 'POST',
					async: false,
					dataType: 'json',
					//cache: false,
					data: {_token: "{{ csrf_token() }}",id:id,action:a},

					success: function (data) {
						if(data==2 ){
							redata();
						}
					},
				});
            }

        }

        //redata();

	</script>
</body>
</html>